package com.gy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gy.entity.User;
import com.gy.vo.UserResultCountVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT " +
            "paper_count, " +
            "patent_count, " +
            "copyright_count, " +
            "awardPersonal_count, " +
            "awardStudent_count, " +
            "material_count, " +
            "publication_count, " +
            "report_count, " +
            "certificateinfo_count, " +
            "other_count, " +
            "longitudinal_project_count, " +
            "horizontal_project_count " +
            "FROM sys_user WHERE user_id = #{userId}")
    UserResultCountVO getUserResultCountByUserId(@Param("userId") Long userId);

    @Update("UPDATE sys_user SET " +
            "avatar = #{avatar}, " +
            "nick_name = #{nickName}, " +
            "phonenumber = #{phoneNumber}, " +
            "email = #{email}, " +
            "title = #{title}, " +
            "department = #{department} " +
            "WHERE user_id = #{userId}")
    int updateUserById(User user);

    @Select("select nick_name from sys_user where user_id=#{userId}")
    String getUserNickNameByUserId(Long userId);

    @Select("SELECT * FROM sys_user WHERE user_id = #{userId}")
    User getUserById(@Param("userId") Long userId);

    @Update("UPDATE sys_user SET password = #{password} WHERE user_id = #{userId}")
    int updatePasswordByUserId(@Param("userId") Long userId, @Param("password") String password);
}
